<?php
// 本类由系统自动生成，仅供测试用途
class ProductAction extends CommonAction {
    public function product(){
	    //dump(M('protype')->select());
		$ptype = $this->_param(3);
		//dump($ptype);
		//$this->assign("pro_type",M('protype')->where("type_id=$ptype")->select());
		//dump($this);
		$this->assign("pro_type",M('protype')->where("type_id=$ptype")->select());
	    $this->assign("product_type_1",M('product')->where("type_id=$ptype and pro_valid=1")->select())->display();
    }

	public function prodetail(){
		$ptype=$this->_param(3);
		$pid=$this->_param(5);

		$this->assign("pro_type",M('protype')->where("type_id=$ptype")->select());
		$this->assign("product_1",M('product')->where("pro_id=$pid")->select())->display();
	}
	
	public function add() {
		$otime = date('Y-m-d H:i:s',time());
		$Order = M('order');	
		if($Order->create()) {
			$Order->order_time = $otime;
			if(false !== $Order->add()){
                $pro= M('product')->find($_POST["product_id"]);
				$msg="用户:{$_POST['cus_name']},手机号为:{$_POST['cus_phone']},购买你的产品:{$pro['pro_name']}({$_POST["product_id"]}),请尽快与其联系！";
				$adm=M('admin')->find($pro['pro_opadmin']);
				$name='';
				if($adm==NULL)$phone='13164355239';else
				 {$name=$adm['adm_realname'];
				 $phone=$adm['adm_phone'];}

				SendMsg($phone,"校购网","订单提醒",$msg);
				
				if($phone!='13164355239')
					{
						if($name!='') $name='-'.$name;else $name='-'.$pro['pro_opadmin'];
						SendMsg('13164355239',"校购网$name","-",$msg);
					}

				$this->success('订单提交成功！');
			}else{
				exit('订单提交失败！'.$tip);
			}
		}
		else{
			exit($Order->getError().' [ <A HREF="javascript:history.back()">返 回</A> ]');
		}
	}
}